package Cplusplus;

/**
 * Created by Martyn on 27.06.14.
 */
public class BinTree
{
    private char info;
    private BinTree lt;
    private BinTree rt;
    BinTree ()
    {
        info = 'n';
        lt = null;
        rt = null;
    }

    public void setinfo(char info1)
    {
        info = info1;
    }
    public char getinfo()
    {
        return info;
    }
    public static boolean isNull(BinTree b)
    {
        return (b == null);
    }
    public static char RootBT (BinTree b)			// для непустого бин.дерева
    {
        if (b == null)
        {
            System.out.println("Error! RootBT(null)");
            System.exit(1);
        }
        return b.info;
    }
    public static BinTree Left (BinTree b)		// для непустого бин.дерева
    {
        if (b == null)
        {
            System.out.println("Error! Left(null)");
            System.exit(1);
        }
        return b.lt;
    }
    public static BinTree Right (BinTree b)		// для непустого бин.дерева
    {
        if (b == null)
        {
            System.out.println("Error! Right(null)");
            System.exit(1);
        }
        return b.rt;
    }
    public static BinTree ConsBT(char x, BinTree lst, BinTree rst)
    {
        BinTree p = new BinTree();
        if ( p != null)	{
            p.info = x;
            p.lt = lst;
            p.rt = rst;
            return p;
        }
        else
        {
            System.out.println("Memory not enough");
            System.exit(1);
        }
        return p;
    }
    public static BinTree Copy(BinTree b)
    {
        if(!isNull(b))
        {
            BinTree p1 = Copy(Left(b));
            BinTree p2 = Copy(Right(b));
            return ConsBT(RootBT(b),p1,p2);
        }
        else
            return null;
    }
}
